/**
 * OpenAction.java
 * @author: liuex
 * 2007-12-28 ����10:15:16
 *
 * note: 
 */
package lex.explorer.file;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;

import javax.swing.KeyStroke;

import org.lex.explorer.file.AbstractFileAction;
import org.lex.explorer.file.FileExplorer;
import org.lex.io.IO;
import org.lex.io.filesystem.traveller.FileProcessor;


public class DeleteAction extends AbstractFileAction
{
	public DeleteAction( FileExplorer fileExplorer )
	{
		super( fileExplorer );
		this.setName( "Delete" );
		this.setAcceleratorKey( KeyStroke.getKeyStroke( KeyEvent.VK_DELETE, 0 ) );
	}

	public void actionPerformed( ActionEvent e )
	{
		int count = this.fileExplorer.getSelectedItemsCount();
		boolean del = this.confirm( "Delete", count + " files will be deleted, are you sure?" );
		if( false == del )
			return;
		this.message( "", "Delete not implement" );
	}

	class DeleteFileOperator implements FileProcessor<Void>
	{
		private StringBuilder buf = null;

		DeleteFileOperator( StringBuilder buf )
		{
			this.buf = buf;
		}

		public Void operate( File file )
		{
			if( null == file || false == file.exists() )
				return null;
			try
			{
				file.delete();
			}
			catch( Exception e )
			{
				buf.append( IO.getCanonicalPath( file ) );
			}
			return null;
		}
	}
}
